'use strict';

/**
 * Created by ybq on 16-1-4.
 */
angular.module('angular.datagrid',[])
    .directive('datagrid', function ($document) {
        return function (scope, element, attrs) {
            element.on("resize",function(){


            var height=attrs.height
            height=!!!height?"inherit":height+"px";
            var thead=element.find("thead").clone().wrap('<table class="'+element[0].className+'" style="position:absolute;margin:0px;padding:0px"></table>');

            angular.forEach(  element.find("td"),function(value,key){
                console.log(value +' '+ key)
                value.style.width=value.scrollWidth
            })
          //  element.find("thead").css("display","none")
           // element.before(thead)
            element.wrap('<div style="height:'+height+';margin:0px;padding:0px;overflow: auto"></div>')
            })
           // thead.
            // change the attribute
            //  attrs.$set('ecoption', scope.ecoption);
            // observe changes to interpolated attribute
            //scope.$watch(attrs.option, function (value) {
            //    console.log('ecoption has changed value to ' + value);
            //    // attrs.$set('ecoption', scope.ecoption);
            //    // 使用
            //
            //    require(
            //        attrs.echart.split(","),
            //        function (ec) {
            //
            //            var myChart = ec.init(element[0],attrs.theme);
            //
            //            myChart.setOption(value);
            //        })
            //});
            // attrs.$$observers[attrs.ngModel].$scope=scope;

        }

    })